package com.pokermind.common.log;

/**
 * 时间消耗日志工具类
 * 自动记录操作的时间消耗
 * 
 * @author PokerMind Team
 */
public class TimeCostLog extends PlainLog {
    
    private final long startTime;
    
    public TimeCostLog(String operationType, String operationName) {
        super();
        this.startTime = System.currentTimeMillis();
        put(operationType, operationName);
    }
    
    /**
     * 生成包含时间消耗的日志字符串
     */
    @Override
    public String toString() {
        long timeCost = System.currentTimeMillis() - startTime;
        put("time_cost", timeCost);
        return super.toString();
    }
    
    /**
     * 获取当前时间消耗（毫秒）
     */
    public long getTimeCost() {
        return System.currentTimeMillis() - startTime;
    }
    
    /**
     * 添加时间消耗字段并返回日志字符串
     */
    public String toStringWithTimeCost() {
        return toString();
    }
}